const db = require('../config/db');

class CourseModel {
  // 根据课程代码获取课程
  static async getCourseByCode(courseCode) {
    const [courses] = await db.query(
      `SELECT * FROM courses WHERE course_code = ?`,
      [courseCode]
    );
    return courses[0];
  }
  
  // 创建课程
  static async createCourse(courseData) {
    const { courseCode, courseName, faculty } = courseData;
    
    const [result] = await db.query(
      `INSERT INTO courses 
       (course_code, course_name, faculty) 
       VALUES (?, ?, ?)`,
      [courseCode, courseName, faculty]
    );
    
    return { id: result.insertId, ...courseData };
  }
}

module.exports = CourseModel;